mui.init({
    pullRefresh : {
        container:"#refreshContainer",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
        down : {
            style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
            color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
            height:'50px',//可选,默认50px.下拉刷新控件的高度,
            range:'100px', //可选 默认100px,控件可下拉拖拽的范围
            offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
            auto: false,//可选,默认false.首次加载自动上拉刷新一次
            callback :function () {
                userInfoData.updateStatus();
                setTimeout(function () {
                    mui('#refreshContainer').pullRefresh().endPulldownToRefresh(false);
                },1000);
            }
        }
    }
});

var userInfoData;
mui.plusReady(function () {
	userInfoData = new Vue({
		el: '#userInfo_list',
		data: {
            loginSta:0,
			user_detail:'',
		},
        mounted(){
            this.updateStatus();
        },
		methods: {
            updateStatus:function(){
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                var self = this;
                mui.ajax({
                    url: api_host + '/api/linxuan/user/checkLoginStatus',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        console.log(JSON.stringify(msg));
                        if (msg.code == 1) {
                            self.loginSta = 1;
                            self.user_detail = msg.data;
                        } else {
                            self.loginSta = 0;
                            mui.toast(msg.msg, {duration: '300'});
                            //跳转到首页
                            setTimeout(function () {
                                mui.back();
                            }, 1000)
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('登录状态请求失败请重试', {duration: '300'});
                    },
                    complete:function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
			edit_sex:function () {
                var self = this;
                var sexPicker = new mui.PopPicker({
                    layer: 1
                });
                sexPicker.setData([
                    {
                        value:'1',text:'男'
                    },
                    {
                        value:'2',text:'女'
                    },
                    {
                        value:'0',text:'保密'
                    },
                ]);
				//PopPicker弹出层显示时禁用下拉刷新
				plus.webview.currentWebview().setPullToRefresh({support:false});
                sexPicker.show(function(selectItems) {
                    self.editInfo('sex',selectItems[0]['value']);
					//PopPicker弹出层关闭时开启下拉刷新
					plus.webview.currentWebview().setPullToRefresh({support:true,style:"circle"});
                });
            },
			edit_addr:function () {
                var self = this;
                var addressVal = '';
                var addressStr = '';
                //显示几层，我们要显示省、市、区，所以我们这里写三层，如果不写默认是一层
                var addressPicker = new mui.PopPicker({
                    layer: 3
                });
				plus.webview.currentWebview().setPullToRefresh({support:false});
                addressPicker.setData(cityData3);
                addressPicker.show(function(selectItems) {
                    //将选择的省、市、区显示到屏幕上
                    for(var i = 0; i < selectItems.length; i++) {
                        addressStr += selectItems[i].text+' ';
                        addressVal += selectItems[i].value+'-';
                    }
                    console.log(addressVal);
                    self.editInfo('position',addressVal);
					plus.webview.currentWebview().setPullToRefresh({support:true,style:"circle"});
                });
            },
			edit_pass:function () {
                mui.openWindow({
                    url: 'changePwd.html',
                    createNew: false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            edit_nickname:function (val) {
                // mui.prompt('请输入新的昵称',val,' ',['确定','取消'],edit_nickname_info,'');
                mui.toast('暂时无法更改，请前往遴选网更改',{ duration:'1000', type:'div'});
            },
            edit_mobile:function () {
				mui.toast('暂时无法更改，请前往遴选网更改',{ duration:'1000', type:'div'});
                //mui.prompt('请输入新的手机号','',' ',['确定','取消'],edit_mobile,'')
            },
            editInfo:function (type,value) {
                var self = this;
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url:api_host+'/api/linxuan/user/edituserinfo',
                    dataType:'json',
                    data:{'field':type,'values':value},
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type:'post',
                    success:function(msg){
                        console.log(msg);
                        mui.toast(msg.msg,{ duration:'1000', type:'div'});
                        if(msg.code == 1){
                            self.updateStatus();
                        }
                    },
                    error:function(xhr,type,errorThrown){
                        mui.toast('修改信息出错，请重试',{ duration:'2000', type:'div'});
                    },
                    complete:function () {
                    }
                });
            }
		}
	})
})


/*function edit_nickname_info(e) {
    if(e.index == 0){
        var new_name = e.value;
        edit_info('username',new_name);
    }else{
        mui.toast('已取消',{ duration:'1000', type:'div'});
    }
}*/

/*function edit_mobile(e){
    if(e.index == 0){
        var mobile = e.value;
        check_mobile(mobile);
    }else{
        mui.toast('已取消',{ duration:'1000', type:'div'});
    }
}*/




//验证手机是否可以用
/*function check_mobile(mobile) {
    var api_host = plus.storage.getItem('HOST_URL');
    mui.ajax({
        url:api_host+'/api/linxuan/user/checkmobile',
        headers:{'User-Token':plus.storage.getItem('UserToken')},
        timeout:3000,
        data:{'mobile':mobile,},
        dataType:'json',
        type:'post',
        success:function(msg){
            if(msg.code == 1){
                fs_code(mobile);
            }else{
                mui.toast(msg.msg,{ duration:'2000', type:'div'});
            }
        },
        error:function(xhr,type,errorThrown){
            mui.toast('检测手机号失败，请联系客服！',{ duration:'2000', type:'div'});
        }
    });
}*/

//发送验证码
/*function fs_code(num) {
    var api_host = plus.storage.getItem('HOST_URL');
    mui.ajax({
        url:api_host+'/api/linxuan/user/sendverify',
        data:{'account':num},
		headers:{'User-Token':plus.storage.getItem('UserToken')},
        dataType:'json',
        type:'post',
        timeout:3000,
        success:function(msg){
            console.log(msg);
            if(msg.code == 1){
                mui.prompt('请输入您收到的验证码','',' ',['确定','取消'],binding_mobile,'')
                mui.toast(msg.msg,{ duration:'1000', type:'div'});
            }else{
                mui.toast(msg.msg,{ duration:'1000', type:'div'});
            }
        },
        error:function(xhr,type,errorThrown){
            mui.toast('系统错误，请联系客服！',{ duration:'2000', type:'div'});
        }
    });
}*/

//点击确定绑定
/*function binding_mobile() {
    if(e.index == 0){
        var wd = plus.nativeUI.showWaiting('正在绑定中');
        var mobile = e.value;
        var api_host = plus.storage.getItem('HOST_URL');
        mui.ajax({
            url:api_host+'/api/linxuan/user/changemobile',
            data:{'mobile':mobile},
			headers:{'User-Token':plus.storage.getItem('UserToken')},
            dataType:'json',
            type:'post',
            timeout:3000,
            success:function(msg){
                if(msg.code == 1){
                    setTimeout(function () {
                        wd.close();
                        mui.toast(msg.msg,{ duration:'2000', type:'div'});
                    },1500)
                }else{
                    mui.toast(msg.msg,{ duration:'1000', type:'div'});
                }
            },
            error:function(xhr,type,errorThrown){
                mui.toast('手机号绑定错误，请联系客服！',{ duration:'2000', type:'div'});
            }
        });
    }else{
        mui.toast('已取消绑定',{ duration:'1000', type:'div'});
    }
}*/

